package org.sport.dbImplement;

import org.sport.dbInterface.GroupOperation;
import org.sport.model.entityModel.GrouptableEntity;
import org.sport.model.entityModel.UsertableEntity;
import org.sport.repository.GrouptableRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Allen on 2017/9/22.
 */
@Service
public class GroupOpeImp implements GroupOperation {

    @Autowired
    GrouptableRepository    grouptableRepository;

    @Override
    public boolean addOneGroup(GrouptableEntity grouptableEntity) {
        if(grouptableEntity != null )
        {
            grouptableRepository.saveAndFlush(grouptableEntity);
            return true;
        }
        else
            return false;
    }

//    @Override
    public boolean updateOneGroupById(GrouptableEntity grouptableEntity) {
        return false;
    }

    @Override
    public boolean delOneGroupById(GrouptableEntity grouptableEntity) {
        if(grouptableEntity != null )
        {
            grouptableRepository.delete(grouptableEntity);
            return true;
        }
        else
            return false;
    }

    @Override
    public GrouptableEntity findById(GrouptableEntity grouptableEntity) {
        return grouptableRepository.findOne(grouptableEntity.getId());
    }

    @Override
    public List<GrouptableEntity> findAllG() {
        return grouptableRepository.findAll();
    }

    @Override
    public List<GrouptableEntity> findByOwnerId(UsertableEntity usertableEntity) {
        return grouptableRepository.findByOwner(usertableEntity);
    }

    @Override
    public List<GrouptableEntity> findByTheam(GrouptableEntity grouptableEntity) {
        return grouptableRepository.findByTheam(grouptableEntity.getTheam());
    }

    @Override
    public List<GrouptableEntity> findByTitle(GrouptableEntity grouptableEntity) {
        return grouptableRepository.findByTitle(grouptableEntity.getTitle());
    }

//    @Override
    public List<GrouptableEntity> findByTitle(UsertableEntity usertableEntity) {
        return null;
    }
}
